﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using FileParser;

namespace _2D_GUI
{
    /// <summary>
    /// Represents classes, methods, and attributes of a given project.
    /// </summary>
    public abstract class C_Shape
    {
        // Shape attributes
        protected C_Shape[] shapeArray;
        protected string shapeName;
        protected Size shapeSize;
        protected Point shapeLocation;
        protected Color shapeColor;
        protected SolidBrush shapeBrush;
        private C_DataStructure originalData;

        /// <summary>
        /// Brief constructor.
        /// Initializes shape attributes.
        /// </summary>
        /// <param name="data"></param>
        /// <param name="size"></param>
        /// <param name="location"></param>
        /// <param name="color"></param>
        /// <param name="shapes"></param>
        public C_Shape(C_DataStructure data, Size size, Point location, Color color, C_Shape[] shapes)
        {
            // Initialize shape attributes
            shapeName = data.GetName();
            originalData = data;
            shapeSize = size;
            shapeLocation = location;
            shapeColor = color;
            shapeArray = shapes;
            shapeBrush = new SolidBrush(color);
        }

        /// <summary>
        /// Adds an inheriting class.
        /// </summary>
        /// <param name="newClass"></param>
        public void AddInheriter(C_Shape newClass)
        {
            C_Shape[] newInher = new C_Shape[1];
            newInher[0] = newClass;
            this.shapeArray = this.shapeArray.Concat(newInher).ToArray();
        }

        /// <summary>
        /// Shape objects must override the Draw method.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public abstract void Draw(object sender, PaintEventArgs e);

        // Determines if two shapes are equal
        /// <summary>
        /// Determines if two shapes are equal.
        /// </summary>
        /// <param name="shape"></param>
        /// <returns>True if equal; False otherwise</returns>
        public bool Equals(C_Shape shape)
        {
            // If parameter is null return false
            if ((object)shape == null)
            {
                return false;
            }

            // Return true if the fields match
            return shapeName == shape.GetName();
        }

        /// <summary>
        /// Gets the color of a shape.
        /// </summary>
        /// <returns>The color of the shape.</returns>
        public Color GetColor()
        {
            return shapeColor;
        }

        /// <summary>
        /// Gets all of the child shapes.
        /// </summary>
        /// <returns>An array of shapes that inherit from this shape.</returns>
        public C_Shape[] GetInheritance()
        {
            return shapeArray;
        }

        /// <summary>
        /// Gets the location of a shape.
        /// </summary>
        /// <returns>The point of the upper, left position of the shape.</returns>
        public Point GetLocation()
        {
            return shapeLocation;
        }

        /// <summary>
        /// Gets the name of a shape.
        /// </summary>
        /// <returns>The name of the shape.</returns>
        public string GetName()
        {
            return shapeName;
        }

        /// <summary>
        /// Gets the number of methods inheriting from a shape.
        /// </summary>
        /// <returns>The number of methods inheriting from this shape.</returns>
        public int GetNumFunctions()
        {
            return originalData.GetNumFunctions();
        }

        /// <summary>
        /// Gets the number of attributes inheriting from a shape.
        /// </summary>
        /// <returns>The number of attributes inheriting from this shape.</returns>
        public int GetNumVariables()
        {
            return originalData.GetNumVariables();
        }

        /// <summary>
        /// Gets the dimensions of a shape.
        /// </summary>
        /// <returns>The size of the shape.</returns>
        public Size GetSize()
        {
            return shapeSize;
        }

        /// <summary>
        /// Changes the color of a shape.
        /// </summary>
        /// <param name="newColor"></param>
        public void SetColor(Color newColor)
        {
            shapeColor = newColor;
            shapeBrush = new SolidBrush(shapeColor);
        }

        /// <summary>
        /// Changes the location of a shape.
        /// </summary>
        /// <param name="newLocation"></param>
        public void SetLocation(Point newLocation)
        {
            shapeLocation = newLocation;
        }

        /// <summary>
        /// Changes the size of a shape.
        /// </summary>
        /// <param name="newSize"></param>
        public void SetSize(Size newSize)
        {
            shapeSize = newSize;
        }
    }
}
